<?php include '../../authorization_check.php' ?>
<?php include '../../checkSecretaryOnly.php' ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>Close Section</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>
</head>
<style type="text/css">
  th {text-align: right}  
</style>
<body>

<?php include 'top.html' ?>

<?php include 'notifier.php' ?>
<?php
  require_once '../../commonutils/db/DBConnectionManager.php';
  
  function closeSection(){

  	if (isset($_POST['btnSubmit']))
	{
		$sectionID = $_POST['group1']; 
		$sqlquery = " delete from section where sectionID = ".$sectionID;
		DBConnectionManager::query($sqlquery);
		$sqlquery = " delete from exam where sectionID = ".$sectionID;
		DBConnectionManager::query($sqlquery);
		echo "<p><font color=blue><b>You have successfully closed the section.</b></font></p>";
		echo "<p><a href=ViewSections.php> View sections. </a></p>";
	}  	
  	
  }
  
  function listSections($programCode, $semesterID){

	$sqlquery = " select s.sectionID, c.courseCode, c.courseName, s.sectionNumber, i.firstname, i.lastname ".
				" from course c, section s, instructor i ".
				" where s.courseCode = c.courseCode and s.instructorID = i.instructorID ".
				" and s.semesterID = ".$semesterID." and c.programCode = ".$programCode.
				" order by courseCode, sectionNumber ";
	
	// echo $sqlquery."<br>"; 

	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td><input type=\"radio\" name=\"group1\" value= \"".$row['sectionID']."\"></td>";
		echo "<td>".$row['courseCode']."</td>";
		echo "<td>".$row['courseName']."</td>";
		echo "<td>".$row['sectionNumber']."</td>";
		echo "<td>".$row['firstname']." ".$row['lastname']."</td>";
		echo "</tr>";		
	}
	echo "</table>";  	
  	
  }
?>
  
<FORM NAME ="form1" METHOD ="POST" ACTION = "CloseSection.php">
<table border=1>
<tr>
<th></th>
<th style="text-align:center">COURSE CODE </th>
<th style="text-align:center">COURSE NAME </th>
<th style="text-align:center">SECTION </th>
<th style="text-align:center">INSTRUCTOR </th>
</tr>

<p>
<?php
	require_once '../../commonutils/db/DBConnectionManager.php';


	closeSection();	
	listSections($programCode, $semesterID);


?>

</p>

<input type="submit" value="Close selected section" name="btnSubmit" onClick="return radioControl(group1)">
<input type="reset" value="Reset" name="btnReset">
  
</p>  


</FORM>

<?php include 'bottom.php' ?>

</body>


</html>